class GroupsController < ApplicationController
  def create
    user = User.find_by_id(session[:user_id])
    groups = Group.new
    groups.name = params[:name]
    groups.description = params[:description]
    user.groups << (groups)
    if groups.valid?
      if groups.save
        flash[:group] = "Your Group has been added"
        redirect_to :controller =>"workspaces", :action =>"profile"
      end
    end
  end
  def join
    user = User.find_by_id(session[:user_id])
    group = Group.find_by_id(params[:with])
    user_group = UserGroup.new
    user.user_groups << (user_group)
    group.user_groups << (user_group)
    if user_group.save
      flash[:join_group] = "You joined #{group.name}'s group"
      redirect_to :controller =>"workspaces", :action =>"profile"
    end
  end
end